﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="add_score_form.aspx.cs" Inherits="SQT.tracnghiem.Ajax.ASP.Class.add_score_form" %>

<%@ Import Namespace="DataAccess" %>
<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <%
        int id = int.Parse(Request.QueryString["id"]);
        int cls = int.Parse(Request.QueryString["cls"]);
        var get_exam = new TblExamController().FetchAll().Where(x => x.ExamId == id).Single();
        var get_student = new TblUserController().FetchAll().Where(x => x.ClassX == cls);
        var get_semester = new TblExamGroupController().FetchAll().Where(x => x.GroupId == get_exam.ExamGroup).First();

        if (get_semester.Semester != 3)
        {
    %>
    <table class="w3-white">
        <thead>
            <tr class="">
                <td rowspan="2" class="name-col w3-deep-purple">Họ tên</td>
                <td colspan="5" class="w3-padding-4 w3-orange w3-text-white"><%=get_exam.ExamName %></td>
            </tr>
            <tr>
                <td class="insert-point-col w3-blue w3-padding-4">Từ vựng</td>
                <td class="insert-point-col w3-indigo w3-padding-4">Ngữ pháp</td>
                <td class="insert-point-col w3-purple w3-padding-4">Nghe</td>
                <td class="insert-point-col w3-green w3-padding-4">Hán tự</td>
                <%--<td class="insert-point-col w3-red w3-padding-4">Giao tiếp</td>--%>
            </tr>
        </thead>
        <tbody>
            <%foreach (TblUser user in get_student)
                {
                    float? write = null, grammar = null, listen = null, kanji = null;
                    var get_score = new TblExamScoreController().FetchAll().Where(x => x.ScoreStudentId == user.UserId && x.ScoreExam == id).ToList();
                    if (get_score.Count != 0)
                    {
                        if (get_score[0].ScoreListen != null)
                            listen = (float)get_score[0].ScoreListen;
                        if (get_score[0].ScoreGrammar != null)
                            grammar = (float)get_score[0].ScoreGrammar;
                        if (get_score[0].ScoreKanji != null)
                            kanji = (float)get_score[0].ScoreKanji;
                        //if (get_score[0].ScoreSpeak != null)
                        //    speak = (float)get_score[0].ScoreSpeak;
                        if (get_score[0].ScoreWrite != null)
                            write = (float)get_score[0].ScoreWrite;
            %>
            <tr class="student">
                <td class="w3-hide student_id"><%=user.UserId %></td>
                <td class="name-col"><%=user.FullName %></td>
                <td class="insert-point-col">
                    <input type="text" class="score" value="<%=write %>" placeholder="?" /></td>
                <td class="insert-point-col">
                    <input type="text" class="score" value="<%=grammar %>" placeholder="?" /></td>
                <td class="insert-point-col">
                    <input type="text" class="score" value="<%=listen %>" placeholder="?" /></td>
                <td class="insert-point-col">
                    <input type="text" class="score" value="<%=kanji %>" placeholder="?" /></td>
                <%--<td class="insert-point-col">
                    <input type="text" class="score" value="<%=speak %>" placeholder="?" /></td>--%>
            </tr>
            <%}
                else
                { %>
            <tr class="student">
                <td class="w3-hide student_id"><%=user.UserId %></td>
                <td class="name-col"><%=user.FullName %></td>
                <td class="insert-point-col">
                    <input type="text" class="score" placeholder="?" /></td>
                <td class="insert-point-col">
                    <input type="text" class="score" placeholder="?" /></td>
                <td class="insert-point-col">
                    <input type="text" class="score" placeholder="?" /></td>
                <td class="insert-point-col">
                    <input type="text" class="score" placeholder="?" /></td>
                <%--<td class="insert-point-col">
                    <input type="text" class="score" placeholder="?" /></td>--%>
            </tr>
            <%} %>
            <%}
                }
                else
                { %>
            <table class="w3-white">
                <thead>
                    <tr class="">
                        <td rowspan="2" class="name-col w3-deep-purple">Họ tên</td>
                        <td colspan="4" class="w3-padding-4 w3-orange w3-text-white"><%=get_exam.ExamName %></td>
                    </tr>
                    <tr>
                        <td class="insert-point-col w3-blue w3-padding-4">Viết</td>
                        <td class="insert-point-col w3-indigo w3-padding-4">Phỏng vấn</td>
                        <td class="insert-point-col w3-purple w3-padding-4">Kiến thức ngôn ngữ</td>
                        <td class="insert-point-col w3-green w3-padding-4">Nghe</td>
                    </tr>
                </thead>
                <tbody>
                    <%foreach (TblUser user in get_student)
                        {
                            float? write = null, listen = null, kanji = null, speak = null;
                            var get_score = new TblExamScoreController().FetchAll().Where(x => x.ScoreStudentId == user.UserId && x.ScoreExam == id).ToList();
                            if (get_score.Count != 0)
                            {
                                if (get_score[0].ScoreListen != null)
                                    listen = (float)get_score[0].ScoreListen;
                                if (get_score[0].ScoreKanji != null)
                                    kanji = (float)get_score[0].ScoreKanji;
                                if (get_score[0].ScoreSpeak != null)
                                    speak = (float)get_score[0].ScoreSpeak;
                                if (get_score[0].ScoreWrite != null)
                                    write = (float)get_score[0].ScoreWrite;
                    %>
                    <tr class="student">
                        <td class="w3-hide student_id"><%=user.UserId %></td>
                        <td class="name-col"><%=user.FullName %></td>
                        <td class="insert-point-col">
                            <input type="text" class="score" value="<%=write %>" placeholder="?" /></td>
                        <td class="insert-point-col">
                            <input type="text" class="score" value="<%=speak %>" placeholder="?" /></td>
                        <td class="insert-point-col">
                            <input type="text" class="score" value="<%=kanji %>" placeholder="?" /></td>
                        <td class="insert-point-col">
                            <input type="text" class="score" value="<%=listen %>" placeholder="?" /></td>
                    </tr>
                    <%}
                        else
                        { %>
                    <tr class="student">
                        <td class="w3-hide student_id"><%=user.UserId %></td>
                        <td class="name-col"><%=user.FullName %></td>
                        <td class="insert-point-col">
                            <input type="text" class="score" placeholder="?" /></td>
                        <td class="insert-point-col">
                            <input type="text" class="score" placeholder="?" /></td>
                        <td class="insert-point-col">
                            <input type="text" class="score" placeholder="?" /></td>
                        <td class="insert-point-col">
                            <input type="text" class="score" placeholder="?" /></td>
                    </tr>
                    <%}}} %>
                </tbody>
            </table>
</body>
</html>
